using UnityEngine;
using UnityEngine.Networking;

public class ItemCooker : NetworkBehaviour
{
	public CharacterInventory inventory;

	public ItemCrafter[] ItemMixes;

	public float UpdateInterval = 1f;

	private float timeTmp;

	private void Start()
	{
		inventory = GetComponent<CharacterInventory>();
	}

	private void Update()
	{
		if (!(inventory == null) && base.isServer)
		{
			UpdateMixer();
		}
	}

	private void checkCook()
	{
		for (int i = 0; i < ItemMixes.Length; i++)
		{
			for (int j = 0; j < ItemMixes[i].ItemNeeds.Length; j++)
			{
				ItemMixes[i].StartBuild = inventory.CheckItem(ItemMixes[i].ItemNeeds[j].Item, ItemMixes[i].ItemNeeds[j].Num);
			}
		}
	}

	private void UpdateMixer()
	{
		if (inventory == null || !(Time.time > timeTmp + UpdateInterval))
		{
			return;
		}
		checkCook();
		timeTmp = Time.time;
		for (int i = 0; i < ItemMixes.Length; i++)
		{
			if (ItemMixes[i].StartBuild && Time.time >= ItemMixes[i].CraftTimeTemp + ItemMixes[i].CraftTime)
			{
				inventory.AddItemByItemDataNoLimit(ItemMixes[i].ItemResult, ItemMixes[i].NumResult, -1, -1);
				for (int j = 0; j < ItemMixes[i].ItemNeeds.Length; j++)
				{
					inventory.RemoveItem(ItemMixes[i].ItemNeeds[j].Item, ItemMixes[i].ItemNeeds[j].Num);
				}
				ItemMixes[i].CraftTimeTemp = Time.time;
			}
		}
	}

	private void UNetVersion()
	{
	}

	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool result = default(bool);
		return result;
	}

	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
	}
}
